<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <script>
        /**
* @param {number[]} nums
* @param {number} target
* @return {number}
*/
        var search = function (nums, target) {
            let length = nums.length;
            let left = 0, right = length - 1;

            let res = func(left, right, target, nums);
            console.log('res',res);
            return res;

        };
        var func = function (left, right, target, nums) {
          
            // return -1;
            console.log(left,right);
            if (left > right) {
                return -1
            }
            let mid = Math.floor(left + (right - left) / 2);
            console.log('mid', mid);

            // console.log(mid);
            if (target == nums[mid]) {
                console.log('target',target);
                console.log('nums[mid]',nums[mid]);
                return mid;
            }
            if (target > nums[mid]) {
                left = mid+1;
            } else {
                right = mid-1;
            }
            return func(left, right, target, nums);
        }
        // search([-1,0,3,5,9,12],9);
        // search([-1,0,3,5,9,12],2);
        search([5],5);

    </script>
</body>

</html>